package com.ccrfid.rmc6.pojo.dto.visitroom;

import com.ccrfid.rmc6.appconfig.jackson.CustomDouble4Serialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.util.List;

public class PrisonRoomDto {
    private Long orgId;
    private String orgName;
    private String orgSn;
    private Integer sortNumber;
    @JsonSerialize(using = CustomDouble4Serialize.class)
    private Double completionRate;
    private List<VisitRecordDto> visitRecordList;

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    public String getOrgSn() {
        return orgSn;
    }

    public void setOrgSn(String orgSn) {
        this.orgSn = orgSn;
    }

    public Integer getSortNumber() {
        return sortNumber;
    }

    public void setSortNumber(Integer sortNumber) {
        this.sortNumber = sortNumber;
    }

    public Double getCompletionRate() {
        return completionRate;
    }

    public void setCompletionRate(Double completionRate) {
        this.completionRate = completionRate;
    }

    public List<VisitRecordDto> getVisitRecordList() {
        return visitRecordList;
    }

    public void setVisitRecordList(List<VisitRecordDto> visitRecordList) {
        this.visitRecordList = visitRecordList;
    }

    public void calcCompletionRate(Integer minStayTime, Integer minFrequency) {
        if (minFrequency <= 0) {
            this.completionRate = 1.0;
        }
        if (visitRecordList != null && visitRecordList.size() > 0) {
            int validCount = 0;
            for (VisitRecordDto recordDto : visitRecordList) {
                if (recordDto.getStayTime() > minStayTime) {
                    validCount ++;
                }
            }
            if (validCount >= minFrequency) {
                this.completionRate = 1.0;
            } else {
                this.completionRate = validCount / minFrequency.doubleValue();
            }
        } else {
            this.completionRate = 0.0;
        }
    }
}
